import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        List<List<Integer>> triangle = new List<List<Integer>>() {
            @Override
            public int size() {
                return 0;
            }

            @Override
            public boolean isEmpty() {
                return false;
            }

            @Override
            public boolean contains(Object o) {
                return false;
            }

            @Override
            public Iterator<List<Integer>> iterator() {
                return null;
            }

            @Override
            public Object[] toArray() {
                return new Object[0];
            }

            @Override
            public <T> T[] toArray(T[] a) {
                return null;
            }

            @Override
            public boolean add(List<Integer> integers) {
                return false;
            }

            @Override
            public boolean remove(Object o) {
                return false;
            }

            @Override
            public boolean containsAll(Collection<?> c) {
                return false;
            }

            @Override
            public boolean addAll(Collection<? extends List<Integer>> c) {
                return false;
            }

            @Override
            public boolean addAll(int index, Collection<? extends List<Integer>> c) {
                return false;
            }

            @Override
            public boolean removeAll(Collection<?> c) {
                return false;
            }

            @Override
            public boolean retainAll(Collection<?> c) {
                return false;
            }

            @Override
            public void clear() {

            }

            @Override
            public List<Integer> get(int index) {
                return List.of();
            }

            @Override
            public List<Integer> set(int index, List<Integer> element) {
                return List.of();
            }

            @Override
            public void add(int index, List<Integer> element) {

            }

            @Override
            public List<Integer> remove(int index) {
                return List.of();
            }

            @Override
            public int indexOf(Object o) {
                return 0;
            }

            @Override
            public int lastIndexOf(Object o) {
                return 0;
            }

            @Override
            public ListIterator<List<Integer>> listIterator() {
                return null;
            }

            @Override
            public ListIterator<List<Integer>> listIterator(int index) {
                return null;
            }

            @Override
            public List<List<Integer>> subList(int fromIndex, int toIndex) {
                return List.of();
            }
        };

        for (int i = 0; i < n; i++) {
            int m = scanner.nextInt();
            List<Integer> array = new ArrayList<>(m);
            for (int j = 0; j < m; j++) {
                int l = scanner.nextInt();
                array.set(j,l);
            }
            triangle.set(i,array);
        }
        Solution solution = new Solution();
        System.out.println(solution.minimumTotal(triangle));
    }
}

class Solution {
    public int minimumTotal(List<List<Integer>> triangle) {
        int n = triangle.size();
        int[][] f = new int[n][n];
        for (int i = 0; i < n; i++) {
            f[n-1][i] = triangle.get(n-1).get(i);
        }
        for (int i = n - 2; i >= 0; i--){
            for (int j = 0; j <= i ; j++) {
                f[i][j] = Math.min(f[i+1][j],f[i+1][j+1]) + triangle.get(i).get(j);
            }
        }
        return f[0][0];
    }
}